package com.engine.zhlx.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;


/**
 * @author dusongsong
 * @date 2023年05月12日 14:20
 */
public class MeetingUtil extends BaseBean {

    /**
     * 获取人员工号
     */
    public static String getUserInfo(String resourceid) {
        RecordSet rs = new RecordSet();
        rs.executeQuery("select lastname,workcode from hrmresource where id=?", resourceid);
        rs.next();
        String lastname = Util.null2String(rs.getString("lastname"));
        String workcode = Util.null2String(rs.getString("workcode"));
        return workcode + "," + lastname;
    }

    /**
     * 获取人员工号
     */
    public static JSONArray getUserList(String resourceid) {
        JSONArray dataList = new JSONArray();
        RecordSet rs = new RecordSet();
        rs.executeQuery("select lastname,workcode from hrmresource where id in (" + resourceid + ")");
        while (rs.next()) {
            JSONObject dataJson = new JSONObject();
            String lastname = Util.null2String(rs.getString("lastname"));
            String workcode = Util.null2String(rs.getString("workcode"));
            dataJson.put("employeeNum", workcode);
            dataJson.put("employeeName", lastname);
            dataList.add(dataJson);
        }
        return dataList;
    }

    /**
     * 会议状态转换 0：草稿,1：待审批,2:正常,3:退回,4:取消,5:结束
     * 会议状态: CANCELLED-取消，NOTSTART-未开始，INPROCESS-进行中，ENDING-已结束
     */
    public static String convertMeetStat(String meetingstatus) {
        String newStatus = "";
        switch (meetingstatus) {
            case "0":
                newStatus = "NOTSTART";
                break;
            case "1":
                newStatus = "NOTSTART";
                break;
            case "2":
                newStatus = "INPROCESS";
                break;
            case "3":
                newStatus = "NOTSTART";
                break;
            case "4":
                newStatus = "CANCELLED";
                break;
            case "5":
                newStatus = "ENDING";
                break;
            default:
        }
        return newStatus;
    }

    /**
     *获取预订会议室
     */
    public static String getAddress() {
        RecordSet rs = new RecordSet();
        String fullDate = DateUtil.getFullDate();
        String strs = "";
        rs.executeQuery("select address from meeting where meetingstatus=2 " +
                "and concat(enddate,' ',endtime,':00')>'"+fullDate+"' group by address");
        while (rs.next()) {
            String address = Util.null2String(rs.getString("address"));
            strs += "".equals(strs) ? address : "," + address;
        }
        return strs;
    }


}
